package com.pxst.merchant.controller;

import com.pxst.merchant.req.MerchantInfoReq;
import com.pxst.merchant.req.MerchantListReq;
import com.pxst.merchant.resp.MerchantInfoResp;
import com.pxst.merchant.resp.MerchantListResp;
import com.pxst.merchant.resp.MerchantSelectListResp;
import com.pxst.merchant.service.SysMerchantInfoService;

import com.pxst.resp.ApiResp;
import com.pxst.resp.PageResp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: @Ryan
 * @Description:主后台系统商户相关接口
 * @CreateTime: 2023-09-11 15:39
 */
@RestController
@RequestMapping("/api/merchant")
@Api(tags = "商户相关接口")
public class SysMerchantInfoController {
    @Autowired
    private SysMerchantInfoService sysMerchantInfoService;

    @GetMapping("/simple")
    @ApiOperation("获取所有商户，供选项列表中展示")
    public ApiResp<List<MerchantSelectListResp>> getMerchantSelectList(@RequestParam List<String> with){
        return sysMerchantInfoService.getMerchantSelectList();
    }

    @GetMapping("/list")
    @ApiOperation("查询商户列表")
    public ApiResp<PageResp<MerchantListResp>> getMerchantList(@ModelAttribute MerchantListReq param) throws NoSuchFieldException, IllegalAccessException {
        System.out.println(param);
        return sysMerchantInfoService.getMerchantInfoList(param);
    }

    @PostMapping("/add")
    @ApiOperation("添加商户")
    public ApiResp<MerchantInfoResp> addMerchant(@RequestBody MerchantInfoReq merchantInfo) throws IllegalAccessException {
        return sysMerchantInfoService.addMerchant(merchantInfo);
    }

    @PostMapping("/update")
    @ApiOperation("编辑商户信息")
    public ApiResp<String> updateMerchant(@RequestBody MerchantInfoReq merchantInfo){

        return sysMerchantInfoService.updateMerchant(merchantInfo);
    }

    @GetMapping("/detail")
    @ApiOperation("根据商户id获取商户信息")
    private ApiResp<MerchantInfoResp> getMerchantInfoById( Long id){
        return sysMerchantInfoService.getMerchantInfoById(id);
    }



}
